package com.aptemo.webetek.server.handlers;

import java.util.ArrayList;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.GetEventsAction;
import com.aptemo.webetek.client.commands.responses.ListResponse;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.server.datastore.DataStoreAPI;
import com.aptemo.webetek.shared.EventBean;

public class EventsHandler
		extends ActionHandler<GetEventsAction, ListResponse<EventBean>>
{

	public EventsHandler(DataStoreAPI service)
	{
		super(service);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return GetEventsAction.class;
	}

	@Override
	public ListResponse<EventBean> invoke(GetEventsAction action) throws BackendException
	{

		String teamId = action.getTeamId();
		String groupId = action.getSportId();

		return new ListResponse<EventBean>((ArrayList<EventBean>) dataService.getEvents(teamId, groupId, action.getDate(), action.getStatus()));

	}
}
